﻿using D.Wx.Dtos;
using D.Wx.Entities;
using D.Wx.Filter;
using D.Wx.IRepository;
using Microsoft.AspNetCore.Mvc;

namespace D.Wx
{
    /// <summary>
    /// 用户
    /// </summary>
    [Route("api/sysWxUser")]
    [ApiController]
    public class SysWxUserController : ControllerBase
    {

        private readonly ISysWxUserRepository _sysWxUserRepository;

        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="sysWxUserRepository"></param>
        public SysWxUserController(ISysWxUserRepository sysWxUserRepository)
        {
            _sysWxUserRepository = sysWxUserRepository;
        }

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns> 
        [HttpGet("queryPage"), TypeFilter(typeof(ActionFilter))]
        public async Task<ApiResult<PageModel<SysWxUserEntityOutput>>> QueryPage([FromQuery] SysWxUserEntityQuery query)
        {
            return new ApiResult<PageModel<SysWxUserEntityOutput>>()
            {
                Data = await _sysWxUserRepository.QueryPage(query)
            };
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost("add"), TypeFilter(typeof(ActionFilter))]
        public async Task<ApiResult<string>> Add([FromBody] SysWxUserEntity entity)
        {
            var res = await _sysWxUserRepository.Add(entity);
            if (res > 0)
            {
                return new ApiResult<string>() { Success = true, StatusCode = StatusCodeEnum.OK, Msg = "添加成功" };
            }
            return new ApiResult<string>() { Success = true, StatusCode = StatusCodeEnum.Error, Msg = "添加失败" };
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost("delete"), TypeFilter(typeof(ActionFilter))]
        public async Task<ApiResult<string>> Delete([FromBody] List<string> ids)
        {
            var res = await _sysWxUserRepository.Delete(ids);
            if (res > 0)
            {
                return new ApiResult<string>() { Success = true, StatusCode = StatusCodeEnum.OK, Msg = "删除成功" };
            }
            return new ApiResult<string>() { Success = true, StatusCode = StatusCodeEnum.Error, Msg = "删除失败" };
        }
    }
}
